<template>
    <breadcrumb>
        <SecondFunc 
            :title="title"
            :formConfig="formConfig"
            :initialData="initialData"
            @optSave="saveData"
            />
    </breadcrumb>
    <dynamicTable
        :title="title"
        :data="data"
        :columns="columns"
        @optEdit="onEdit"
        @optDel="onDel"
        @optSave="saveData"
    />
</template>

<script setup>
import { onMounted, ref } from 'vue'
import breadcrumb from '@/components/common/breadcrumb/index.vue'
import SecondFunc from '@/components/common/secondFunc/index.vue'
import dynamicTable from '@/components/common/dynamicTable/index.vue'
import { changeIsShowCreateButton, changeCurLabel } from '@/assets/js/common'
import { getBugList } from '@/api/index.js'



let title = ref('bug')
let data = ref([{
    index: 1,
    id: 1,
    name: '缺陷1',
    type: '功能缺陷',
    path: '步骤1 --> 步骤2',
    level: '高',
    rank: '高',
    project: '项目1',
    createTime: '2023-08-01',
    updateTime: '2023-08-01',
    state: '待处理',
    operator: '李斯',
    owner: '张三'
    },
    {
    index: 2,
    id: 2,
    name: '缺陷2',
    type: '功能缺陷',
    path: '步骤1 --> 步骤2 --> 步骤3',
    level: '中',
    rank: '中',
    project: '项目2',
    createTime: '2025-08-01',
    updateTime: '2025-08-01',
    state: '待处理',
    operator: '嬴政',
    owner: '巨子'
    },
])
let columns = ref([
    {
        prop: 'index',
        label: '序号',
        width: '80',
        fixed: "fixed"
    },
    {
        prop: 'name',
        label: '标题',
        width: '120',
        fixed: "fixed"
    },
    {
        prop: 'type',
        label: '类型',
        width: '120'
    },
    {
        prop: 'rank',
        label: '优先级',
        width: '120'
    },
    {
        prop: 'level',
        label: '等级',
        width: '120'
    },
    {
        prop: 'state',
        label: '状态',
        width: '100'
    },
    {
        prop: 'project',
        label: '项目',
        width: '120'
    },
    {
        prop: 'path',
        label: '步骤',
        width: '400'
    },
    {
        prop: 'startTime',
        label: '开始时间',
        width: '160'
    },
    {
        prop: 'endTime',
        label: '结束时间',
        width: '160'
    },
    {
        prop: 'developer',
        label: '开发人员',
        width: '180'
    },
    {
        prop: 'tester',
        label: '测试人',
        width: '180'
    },
    {
        prop: 'version',
        label: '发现版本',
        width: '180'
    },
    {
        prop: 'linkPrd',
        label: '关联需求',
        width: '180'
    },
    {
        prop: 'env',
        label: '环境',
        width: '120'
    },
    {
        prop: 'platform',
        label: '发现平台',
        width: '180'
    },
    {
        prop: 'deviceType',
        label: '设备类型',
        width: '180'
    },
    {
        prop: 'operator',
        label: '处理人',
        width: '100'
    },
    {
        prop: 'solution',
        label: '解决方法',
        width: '180'
    },
    {
        prop: 'owner',
        label: '维护人',
        width: '100'
    },
    {
        prop: 'createTime',
        label: '创建时间',
        width: '160'
    },
    {
        prop: 'updateTime',
        label: '更新时间',
        width: '160'
    }
])
let formConfig = ref([
    {
        label: '标题',
        name: 'name',
        ktype: "input",
        styleSet: '',
        required: true,
    },
    {
        label: '类型',
        name: 'type',
        ktype: 'select',
        options: [
            {label: "功能缺陷", value: "功能缺陷"},
            {label: "性能缺陷", value: "性能缺陷"},
            {label: "安全缺陷", value: "安全缺陷"},
        ],
        styleSet: '',
        required: true,
    },
    {
        label: '等级',
        name: 'level',
        ktype: 'select',
        options: [
            {label: "严重", value: "P0"},
            {label: "一般", value: "P1"},
            {label: "提示", value: "P2"},
        ],
        styleSet: '',
        required: true,
    },
    {
        label: '步骤',
        name: 'path',
        ktype: 'textarea',
        styleSet: '',
    },
    {
        label: '状态',
        name: 'state',
        ktype: 'select',
        options: ['忽略','待处理', '处理中', '已解决','已关闭','已重复','设计如此','无法复现','已修复',''],
        styleSet: '',
        required: true,
    },
    {
        label: '处理人',
        name: 'operator',
        ktype: 'input',
        styleSet: '',
    },
    {
        label: '维护人',
        name: 'owner',
        ktype: 'input',
        styleSet: '',
    },

])

onMounted(() => {
    changeCurLabel("缺陷管理") 
    queryList()
})

function queryList(){
    try {
        getBugList().then((res)=>{
            data.value = res.data
        })
    } catch (error) {
        console.error('Error querying api list:', error)
    }
}

function onEdit(row) {
    console.log('编辑', row)
    // todolist
}

function onDel(row) {
    console.log('删除', row)
    // todolist
}

function saveData(row) {
    console.log('保存', row)
    // todolist
}



</script>